import R from "ramda";
// Chat只管发送数据和接收数据的操作, 具体该何时发送数据,交由Room决定
class Chat {
  constructor(option) {
    let user = R.prop("user", option);
    let assistant = R.prop("assistant", option);
    this.user_id = R.prop("id", user);
    this.user_avatar = R.prop("avatar", user);
    this.user_name = R.prop("name", user);
    this.assistant_id = R.prop("id", assistant);
    this.assistant_avatar = R.prop("avatar", assistant);
    this.assistant_name = R.prop("name", assistant);
    this.room_id = R.prop("room_id", option);
  }
  message;
  user_id;
  user_avatar;
  user_name;
  assistant_id;
  assistant_avatar;
  assistant_name;
  room_id;
  talk_list = new Proxy([],{
    get: function (target, prop) {
      if (prop === "push") {
        return function (value) {
          console.log("receive message:", value);
          target.push(value);
        };
      }
      return target[prop];
    },
    set: function (target, prop, value) {
      console.log("receive message:", value);
      target.push(value);
    },
  })
  word_list = new Proxy([], {
    get: function (target, prop) {
      if (prop === "push") {
        return function (value) {
          console.log("receive word(get):", value);
          target.push(value);
        };
      }
      return target[prop];
    },
    set: function (target, prop, value) {
      console.log("receive word(push):", value);
      target.push(value);
    },
  });
  onSend(message, handler) {
    return handler(message);
  }
  receive(word) {
    this.word_list.push(word);
  }
  stopReceive() {}
}

export default Chat;
